package com.hospital.demo.service.impl.gaoyuran;

import com.hospital.demo.enums.ExceptionCodeEnums;
import com.hospital.demo.exception.HospitalException;
import com.hospital.demo.model.gaoyuran.Equipment;
import com.hospital.demo.service.gaoyuran.EquipmentSer;
import com.hospital.demo.mapper.gaoyuran.EquipmentMapper;
import com.hospital.demo.util.ResultUtils;
import com.hospital.demo.util.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;


@Service
public class EquipmentImpl implements EquipmentSer {


    @Autowired
    private EquipmentMapper equipmentMapper;



    @Override
    public Equipment get(Integer meid) {
        return equipmentMapper.get(meid);
    }

    //更新器材信息
    @Override
    public int addEquipment(Equipment equipment) {
        try {
            equipmentMapper.insert(equipment);
        } catch (Exception e) {
            throw new HospitalException(ExceptionCodeEnums.INSERT_FAIL);
        }
        return 0;
    }

    //更新器材信息
    @Override
    public int upDateEquipment(Equipment equipment) {
        try {
            equipmentMapper.updateByPrimaryKey(equipment);
        } catch (Exception e) {
            throw new HospitalException(ExceptionCodeEnums.UPDATE_FAIL);
        }
        return 0;
    }

    //查询全部器材信息
    @Override
    public List<Equipment> findallequipment() {
        return equipmentMapper.findAll();
    }

    //查询全部未使用器材信息
    @Override
    public List<Equipment> findallequipmentno() {
        return equipmentMapper.findAllno();
    }

    //通过id删除器材信息
    @Override
    public int delEquipmentById(Integer meid) {
        return equipmentMapper.deleteByPrimaryKey(meid);
    }
}

